package com.springboot.service.wangyi;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.downloader.HttpClientDownloader;
import us.codecraft.webmagic.processor.PageProcessor;
import us.codecraft.webmagic.proxy.Proxy;
import us.codecraft.webmagic.proxy.SimpleProxyProvider;

import java.util.Date;
import java.util.Map;

/**
 * @ClassName WangYiService
 * @Description
 * @Author zyj
 * @Date 2022/7/7 15:18
 * @Version 1.0
 **/
@Service
@Slf4j
public class WangYiService {

    // 初始地址, 褐言喜欢的音乐id 148174530
    public static final String START_URL = "http://music.163.com/playlist?id=3233164347";
    @Autowired
    private NetEaseMusicPageProcessor netEaseMusicPageProcessor;

    @Async("taskExecutor")
    public void yunMusic() {
        long start = System.currentTimeMillis();
        final String ip = "forward.xdaili.cn";//这里以正式服务器ip地址为准
        final int port = 80;//这里以正式服务器端口地址为准

        //以下订单号，secret参数 须自行改动
        HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
        httpClientDownloader.setProxyProvider(SimpleProxyProvider.from(new Proxy("103.46.128.49", 30449)));

        Spider.create(netEaseMusicPageProcessor)
                .addUrl(START_URL)
                //.setDownloader(httpClientDownloader)
                //.thread(5)
                //.addPipeline(netEaseMusicPipeline)
                .run();
        long end = System.currentTimeMillis();
        System.out.println("爬虫结束,耗时--->" + NetEaseMusicUtils.parseMillisecone(end - start));
    }



}
